require(['loading'], function(loading) {
	
	var brackFlag=0;
	var params = getUrlParams();
	var orderId = params.orderId?params.orderId:'';

	//应用实例化
	var llPay = new Vue({
		el: '#lianlianPay',
		data: {
			data: [],
			queryCardBin: [],
			authUserListData:[],
			payerBankNumRight:'',
			payerIdNumRight:'',
			payNameRight:'',
			orderNo:'',
			isbankCardNos:false,
			showLoading: false,
			orderInfoUrl: wxUrl + '/v3.2/pay/topay',
			queryCardBinUrl: wxUrl + '/v3.2/lianlianAuth/queryCardBin',
			authUserListUrl: wxUrl + '/v3.2/lianlianAuth/authUserList',
			payFormInfoUrl: wxUrl + '/v3.2/lianlianAuth/payFormInfo',
			item: {
				params:{
					orderId:orderId,
					token: token,
					userToken:userToken
				}
			}
		},
		ready: function() {
			this.getPayOrderInfo();
			this.authUserList();
	    },
		methods: {
			getPayOrderInfo: function() {
				this.$http.get(this.orderInfoUrl, this.item)
				.then(function(response) {
					var result = JSON.parse(response.body);
					this.$set("data",result.data);
					this.$set("orderNo",result.data.orderNo);
				});
			},
			authUserList: function(){
				this.$http.get(this.authUserListUrl, this.item)
				.then(function(response) {
					var result = JSON.parse(response.body);
					this.$set("authUserListData",result.data.list);
					if(result.data.list.length > 0){
						//this.isbankCardNos = true;
						this.$set("isbankCardNos",true);
					}
				});
			},
			queryCardBin: function(){
				var params = {};
				params.cardNo = this.payerBankNumRight;
				params.token = token,
				params.userToken = userToken;
				console.info(params)
				this.$http.get(this.queryCardBinUrl, {'params':params})
				.then(function(response) {
					var result = JSON.parse(response.body);
					this.$set("queryCardBin",result.data);
				});
			},
			remarkSubmite: function(){
				/// 验证手机号和电话号码还有银行卡号
				var params = {};
				params.bankCardNo = this.payerBankNumRight;
				params.idNo = this.payerIdNumRight;
				params.trueName = this.payNameRight;
				params.orderNo = this.orderNo;
				params.token= this.item.params.token;
				params.userToken = this.item.params.userToken;

				this.$http.get(this.payFormInfoUrl, {'params':params})
				.then(function(response) {
					var result = JSON.parse(response.body);
					if (result.code == 0) {
						$("#jumpFormDiv").html(result.data.paymentInfo)
						$("#payBillForm").submit();
					}
				});
			},
			selectBankNo:function(e){
				var id = $(e.currentTarget).attr("id");
				var infoArr = this.authUserListData;
				for (let index in infoArr) {
					if (id == infoArr[index].id) {
						this.$set("payerBankNumRight",infoArr[index].bankCardNo);
						this.$set("payerIdNumRight",infoArr[index].idNo);
						this.$set("payNameRight",infoArr[index].trueName);
						break;
					}
				}
				this.cloaseSelectCard();
			},
			selectCard: function(){
				brackFlag = brackFlag+1;
				$("#areaMask").fadeIn();
				$("#areaLayer").animate({"bottom": 0});
			},
			cloaseSelectCard: function(){
				brackFlag = brackFlag-1;
				$("#areaMask").fadeOut();
				$("#areaLayer").animate({"bottom": "-100%"});
			}
		}
	});
	
	history.pushState({}, document.title, null);
	pushVHistory(self_base_path+"/wantBuy/payOrder.html?orderId=" + orderId);
	window.addEventListener("popstate", function() {
		if(brackFlag<1){
			goBackVHistory();
		}else{
			history.pushState({}, document.title, null);
			llPay.cloaseSelectCard();
		}
	});
});

/**
var outerOrderId =  params.orderId?params.orderId:'';
// 为可控制返回指定页面所有添加pushState
history.pushState({}, document.title, null);
pushVHistory(self_base_path+"/userCenter/myOrder/orderDetail.html?orderId=" + outerOrderId);
window.addEventListener("popstate", function() {
    // 跳转到订单列表页面
	goBackVHistory();
});
**/